package com.sambo.inspection.adapter;

import android.content.Intent;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sambo.inspection.R;
import com.sambo.inspection.activity.ImageShowActivity;
import com.sambo.inspection.activity.VideoPlayActivity;
import com.sambo.inspection.bean.MediaFileBean;
import com.sambo.inspection.common.image.ImageLoader;

import java.util.List;

public class MediaListAdapter extends BaseQuickAdapter<MediaFileBean, BaseViewHolder> {

    public MediaListAdapter(List<MediaFileBean> mDatas) {
        super(R.layout.item_media, mDatas);
    }

    @Override
    protected void convert(BaseViewHolder helper, MediaFileBean item) {

        ImageLoader.getInstance().displayImage(mContext, item.getUrl(), helper.getView(R.id.fiv));

        if (item.getMediaType() == 2) {

            helper.setVisible(R.id.tv_duration, true);

            helper.setOnClickListener(R.id.fiv,
                    new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            Intent intent = new Intent(mContext, VideoPlayActivity.class);
                            intent.putExtra("mediaUrl", item.getUrl());
                            mContext.startActivity(intent);
                        }
                    });
        } else {

            helper.setVisible(R.id.tv_duration, false);

            helper.setOnClickListener(R.id.fiv,
                    new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            Intent intent = new Intent(mContext, ImageShowActivity.class);
                            intent.putExtra("imageUrl", item.getUrl());
                            mContext.startActivity(intent);
                        }
                    });
        }
    }
}
